#include "futurescene.h"

Primitive* FutureScene::ix( const Ray &r, Point &p, Vector &n )
{
    double DMin = DBL_MAX;
    int primIdx;
    #pragma mta assert parallel
    #pragma mta loop future
    for( int i=0; i<primitiveCt; i++ )
    {
        double D = primitives[i]->ix( r );
        if( D > EPS )
        {
            double d = readfe( &DMin );
            if( D < d )
            {
                primIdx = i;
                p = r.p( D );
                n = primitives[i]->n( p, r.t0() );
                writeef( &DMin, D );
            }
            else
                writeef( &DMin, d );
        }
    }
    if( DMin == DBL_MAX )
        return NULL;
    else
        return primitives[primIdx];
}
